package com.zy.cat.entity.run.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.zy.cat.entity.run.DailyStepCoinsHistory;

public interface DailyStepCoinsHistoryRepository extends JpaSpecificationExecutor<DailyStepCoinsHistory>,  JpaRepository<DailyStepCoinsHistory, String> {
	DailyStepCoinsHistory findByPidAndFid(String pid,String fid);
	
	/**
	 * 
	 * @info 获取加速金币信息
	 * @author Link
	 * @date 2019-11-30 15:46
	 * @param pid
	 * @param sid
	 * @return
	 */
	@Query("from DailyStepCoinsHistory where pid=:pid and sid=:sid and ctype>0")
	List<DailyStepCoinsHistory> getStepSpeedInfo(@Param("pid")String pid,@Param("sid")String sid);
	
	/**
	 * 
	 * @info 获取今日已经兑换的步数
	 * @author Link
	 * @date 2019-11-30 15:49
	 * @param pid
	 * @param sid
	 * @return
	 */
	@Query(nativeQuery = true,value="select IFNULL(SUM(dcount),0) dcount from zy_cat_run_step_convert_history where pid=:pid and dstatus=1 and ctype=0 and stime>=CURDATE()")
	Integer getDailyStepsCoinsInfo(@Param("pid")String pid);
	
	/**
	 * 
	 * @info 获取最后四次金币领取信息
	 * @author Link
	 * @date 2019-11-30 16:07
	 * @param pid
	 * @return
	 */
	@Query(nativeQuery = true,value="select * from zy_cat_run_step_convert_history where pid=:pid  and stime>=CURDATE() order by stime desc limit 4")
	List<DailyStepCoinsHistory> getDailyStepsInfo(@Param("pid")String pid);
}

